﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using ZHDJ.Core.Util;

namespace ZHDJ.Data.Models.Org
{
    /// <summary>
    /// 组织管理员
    /// </summary>
    public class PartyOrgBranchAdmin : EntityBase
    {
        /// <summary>
        /// 组织ID
        /// </summary>
        public string BranchID { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public string LoginID { get; set; }

        #region 数据操作
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static void UpdateAdmins(string branchId,string[] admins)
        {
            var para = new List<MySqlParameter>
            {
                new MySqlParameter()
                {
                    DbType = DbType.String,
                    ParameterName = "BranchID",
                    Value = branchId
                }
                
            };
            int index = 0;
            var sql = new StringBuilder(@"delete from tblpartyorgbranchadmin where  BranchID=?BranchID;   ");
            foreach (var item in admins)
            {
                sql.AppendFormat(" insert into tblpartyorgbranchadmin(ID,BranchID,LoginID) values (?ID{0},?BranchID,?LoginID{0});", index);
                para.Add(new MySqlParameter()
                {
                    DbType = DbType.String,
                    
                    ParameterName = "ID" + index,
                    Value = StringHelper.NewID
                });
                para.Add(new MySqlParameter()
                {
                    DbType = DbType.String,

                    ParameterName = "LoginID" + index,
                    Value = item
                });
                index += 1;
            }
             MySqlHelper.ExecuteNonQuery(sql.ToString(), para.ToArray());
        }
        #endregion
    }
}
